<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>41、生命周期(旧)_父组件render流程</title>
</head>
<body>
  <div id="test"></div>

  <script crossorigin src="https://unpkg.com/react@16/umd/react.development.js"></script>
  <script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
  <script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>
  <script src="https://cdn.staticfile.org/prop-types/15.6.1/prop-types.js"></script>

  <script type="text/babel">
    // 让A和B形成父子关系，A是父组件，B是子组件
    class A extends React.Component {
      // 初始化状态
      state = {carName: '奔驰'}

      changeCar = () => {
        this.setState({carName: '奥拓'})
      }
    
      render() {
        return (
          <div>
            <div>我是A组件</div>
            <button onClick={this.changeCar}>换车</button>
            <B carName={this.state.carName} />
          </div>
        )
      }
    }

    class B extends React.Component {
      // 组件将要接受新的props的钩子
      componentWillReceiveProps(props) {
        console.log('B-componentWillReceiveProps', props)
      }

      shouldComponentUpdate() {
        console.log('B-shouldComponentUpdate')
        return true
      }

      componentWillMounted() {   // Nesc@123456
        console.log('B-shouldComponentUpdate')
        return true
      }
      render() {
        return (
          <div>我是B组件，接收到的车是：{this.props.carName}</div>
        )
      }
    }
    ReactDOM.render(<A />, document.getElementById('test'))
  </script>
</body>
</html>